package ac2.util.serial.packets;

import ac2.util.TemperatureReadingConverter;
import ac2.util.TemperatureReadingConverter.TemperatureFormat;
import ac2.util.sensors.sht11.SHT11TemperatureReadingConverter;

public class SetTemperaturePacket extends AC2Packet {

	private int temperature = 0;
	public SetTemperaturePacket(double temperature, byte targetNode)
	{
		super(targetNode, (byte)0x02);
		TemperatureReadingConverter converter = new SHT11TemperatureReadingConverter();
		
		this.temperature = converter.ConvertTemperature(temperature, TemperatureFormat.Fahrenheit);
	}
	
	public SetTemperaturePacket(byte[] packet) throws Exception
	{
		super(packet);
	}
	
	@Override
	protected void fillBody(byte[] packet, int start, int length) {
		System.out.println("Raw Temperature is " + temperature);
		
		
		// Temperature is first 2 bytes of the body
		packet[start++] = (byte) ((temperature & 0xFF00) / 0x100);
		packet[start++] = (byte) (temperature & 0xFF);
		
		// Last byte is unused
		packet[start++] = 0x00;
	}
	
	@Override
	protected void parseBody() {
		// NOT DOING ANYTHING WITH THIS...SENDING ONLY
		
	}



}
